
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>购物车</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            color: #333;
            padding: 20px;
        }
        h1 {
            color: #28a745;;
            text-align: center;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        th, td {
            padding: 12px;
            text-align: center;
            border: 1px solid #ccc;
        }
        th {
            background-color: #28a745;
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        tr:hover {
            background-color: #e2e6ea;
        }
        form {
            display: inline;
        }
        input[type="number"] {
            width: 60px;
            padding: 5px;
            border-radius: 3px;
            border: 1px solid #ccc;
            margin-right: 5px;
        }
        input[type="submit"] {
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            padding: 6px 12px;
            transition: background-color 0.3s;
        }
        input[type="submit"]:hover {
            background-color: #218838;
        }
        a {
            display: inline-block;
            margin: 10px 5px;
            text-decoration: none;
            color: #007bff;
            padding: 8px 16px;
            border: 1px solid #007bff;
            border-radius: 5px;
            transition: background-color 0.3s, color 0.3s;
        }
        a:hover {
            background-color: #007bff;
            color: white;
        }
    </style>
</head>
<body>
<h1>购物车</h1>
<table>
    <tr>
        <th>产品名称</th>
        <th>产品价格</th>
        <th>数量</th>
        <th>操作</th>
    </tr>
    <c:set var="totalPrice" value="0" />
    <c:forEach var="item" items="${cart.values()}">
        <tr>
            <td>${item.product.name}</td>
            <td>${item.product.price}</td>
            <td>
                <form action="cart" method="get">
                    <input type="hidden" name="action" value="update">
                    <input type="hidden" name="id" value="${item.product.id}">
                    <input type="number" name="stock" value="${item.stock}" min="1" />
                    <input type="submit" value="更新">
                </form>
            </td>
            <td>
                <a href="cart?action=remove&id=${item.product.id}">删除</a>
            </td>
        </tr>
        <c:set var="totalPrice" value="${totalPrice + (item.product.price * item.stock)}" />
    </c:forEach>
</table>
<p style="text-align: center; font-size: 18px;">总价格: ${totalPrice}</p>
<p style="text-align: center;">
    <a href="products">继续购物</a>
    <a href="cart?action=clear">清空购物车</a>
    <a href="cart?action=checkout">付账</a>
</p>
</body>
</html>